package com.four.marketing.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.four.marketing.entity.Configure;
import com.four.marketing.entity.Group;
import com.four.marketing.entity.Seckill;
import com.four.marketing.service.ConfigureService;
import com.four.marketing.vo.ConfigureVo;
import com.four.marketing.vo.GroupVo;
import com.guli.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 侯新伟
 * @since 2021-12-14
 */
@RestController
@RequestMapping("mark/configure")
public class ConfigureController {

    @Autowired
    private ConfigureService configureService;

    /**
     * 秒杀配置的列表查询
     * 分页 模糊 状态
     * @param vo
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/configureList")
    public IPage<Configure> getConfigureList(@RequestBody ConfigureVo vo,
                                             @RequestParam(value = "page",defaultValue = "1")Integer page,
                                             @RequestParam(value = "size",defaultValue = "3")Integer size){

        return configureService.getConfigureList(vo,page,size);
    }

    /**
     * 添加秒杀配置
     * @param configure
     * @return
     */
    @PostMapping("/addConfigure")
    public R addConfigure(@RequestBody Configure configure){
        configureService.addConfigure(configure);
        return R.ok();
    }

    /**
     * 根据秒杀配置名查询
     * 唯一
     * @param conName
     * @return
     */
    @GetMapping("findConfigureBName/{conName}")
    public R findConfigureBName(@PathVariable("conName")String conName){
        Configure configure=configureService.findConfigureBName(conName);
        return R.ok().put("configure",configure);
    }

    /**
     * 根据id删除秒杀配置
     * @param concId
     * @return
     */
    @DeleteMapping("delConfigureById/{conId}")
    public R delConfigureById(@PathVariable("conId")Integer concId){
        configureService.delConfigureById(concId);
        return R.ok();
    }

    /**
     * 根据id获取秒杀配置的id
     * @param conId
     * @return
     */
    @GetMapping("getConfigureById/{conId}")
    public R getConfigureById(@PathVariable("conId")Integer conId){
        Configure configure=configureService.getConfigureById(conId);
        return R.ok().put("configure",configure);
    }

    /**
     * 修改秒杀配置
     * @param configure
     * @param conId
     * @return
     */
    @PutMapping("/updateConfigure/{conId}")
    public R updateConfigure(@RequestBody Configure configure,@PathVariable("conId")Integer conId){
        configureService.updateConfigure(configure,conId);
        return R.ok();
    }
}
